package com.gingko.duominuo.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.gingko.duominuo.R
import com.gingko.duominuo.databinding.ActivityMainBinding
import com.gingko.duominuo.ui.fragment.TaskFragment
import com.gingko.duominuo.ui.fragment.UserFragment
import com.gingko.duominuo.ui.fragment.WorkOrderFragment
import com.gingko.duominuo.utils.exitAPP
import com.gingko.duominuo.utils.logi
import com.gingko.duominuo.utils.showFragment
import com.gingko.duominuo.viewmodel.BaseViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BaseActivity() {

    private val mViewBinding by lazy { ActivityMainBinding.inflate(layoutInflater) }

    override fun getContentView(): View {
        return mViewBinding.root
    }

    override fun getViewModel(): BaseViewModel? {
        return null
    }

    override fun initView(savedInstanceState: Bundle?) {
        mViewBinding.rgNavigation.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.rb_task -> showFragment<TaskFragment>(R.id.fl_container)
                R.id.rb_work_order -> showFragment<WorkOrderFragment>(R.id.fl_container)
                R.id.rb_user -> showFragment<UserFragment>(R.id.fl_container)
            }
        }
        showFragment<TaskFragment>(R.id.fl_container)
        getViewModel()?.loadingLiveData?.observe(this) {
            "activity--isShowLoading:$it".logi("------------>")
            if (it) {
                showLoading()
            } else {
                dismissLoading()
            }
        }
    }

    override fun onBackPressed() {
//        super.onBackPressed()
        exitAPP()
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, MainActivity::class.java)
            context.startActivity(starter)
        }
    }
}